//
//  OAuthViewController.swift
//  HMWeibo
//
//  Created by HuaMou.Chen on 15/11/29.
//  Copyright © 2015年 HuaMou.Chen. All rights reserved.
//

import UIKit

class OAuthViewController: UIViewController {
    
    private lazy var webView = UIWebView()
    
    // MARK: - 关闭登录界面
    @objc private func close() {
       dismissViewControllerAnimated(true, completion: nil)
    }
    
    /// 自动填充账号密码
    @objc private func autoFill() {
        let js = "document.getElementById('userId').value = '13580416037';" + "document.getElementById('passwd').value = 'chenhuamou';"
        
        // 让 webview 执行 js
        webView.stringByEvaluatingJavaScriptFromString(js)
    }
    
    
    override func loadView() {
        view = webView
        title = "新浪授权登录"
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "关闭", style: .Plain, target: self, action: "close")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "自动填充", style: .Plain, target: self, action: "autoFill")
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        webView.loadRequest(NSURLRequest(URL: NetworkTools.shareNetworkTools.oauthURL))
    }
}
